var app = getApp();
var baseUrl = app.globalData.host;
Component({
  data: {
    showModal:false,
    batchLeftIds:'',
    batchContentIds:'',
    batchRightIds:'',
    list: [
      {
        name:'苹果',
        id: '202518'
      },
      {
        name:'板栗',
        id: '202519'
      },
      {
        name:'大枣',
        id: '202521'
      },
      {
        name:'兔皮',
        id: '202509'
      },
      {
        name:'玉米',
        id: '202501'
      },
      {
        name:'貉皮',
        id: '202502'
      },
      {
        name:'貂皮',
        id: '202504'
      },
      {
        name:'花生',
        id: '252505'
      },
      {
        name:'大蒜',
        id: '202505'
      },
      {
        name:'花生',
        id: '202514'
      },
      {
        name:'榛子',
        id: '202515'
      },
      {
        name:'人参',
        id: '202516'
      },
      {
        name:'绵羊绒',
        id:'202529',
      },
      {
        name:'山羊绒',
        id:'202530',
      },
      {
        name:'狐狸皮',
        id:'202503',
      }
    ],
    lists:[
      {
        name:'羊奶收购',
        id: '202517'
      },
      {
        name:'酥梨收购',
        id: '0026'
      },
      {
        name:'花椒收购',
        id: '202507'
      },
      {
        name:'大茧收购',
        id: '202513'
      },
      {
        name:'水产品销售',
        id: '202510'
      },
      {
        name:'黄花菜收购',
        id: '202506'
      },
      {
        name:'菇腿(干菇)',
        id: '202524'
      },
      {
        name:'花菇(干菇)',
        id: '202525'
      },
      {
        name:'炒货收购行业',
        id: '2025018'
      },
      {
        name:'柿饼收购加工',
        id: '202527'
      },
      {
        name:'茶叶收购行业',
        id: '202512'
      },
      {
        name:'芦柑收购行业',
        id: '202511'
      },
      {
        name:'水产饲料销售',
        id: '252506'
      },
      {
        name:'柿饼加工、收购',
        id: '202520'
      },
      {
        name:'鲜菇(袋料菇)',
        id: '202523'
      }
    ],
    listss:[
      {
        name:'红香菌(干菇)',
        id: '202526'
      },
      {
        name:'羊绒收购(含初加工)',
        id: '202528'
      },
      {
        name:'粮食收购行业(小麦)',
        id: '202508'
      },
      {
        name:'光面袋料干菇(通货)和大片袋料菇(次品)',
        id: '202522'
      }
    ],
    batchName:'请选择加工种类',
    licenses: ["请选择","新客户", "老客户"],
    licenseIndex: 0,
    formData: {
      batchIds:''
    },
  },
  methods: {
    // 外面的弹窗
    btn:function () {
      var batchIds = this.data.formData.batchIds;
      var list = this.data.list;
      var lists = this.data.lists;
      var listss = this.data.listss;
      for (let i = 0; i < list.length; i++) {
        if(batchIds.length<=0)
        {
          this.data.list[i].checked = false
        }
        else
        {
          for (let index = 0; index < batchIds.length; index++) {
            if(parseInt(batchIds[index]) === parseInt(list[i].id))
            {
              this.data.list[i].checked = true
              break;
            }
            else{
              this.data.list[i].checked = false
            }
          }
        }
      }
    for (let j = 0; j < lists.length; j++) {
      if(batchIds.length<=0)
      {
        this.data.lists[j].checked = false
      }
      else
      {
        for (let index = 0; index < batchIds.length; index++) {
          if(parseInt(batchIds[index]) === parseInt(lists[j].id))
          {
            this.data.lists[j].checked = true
            break;
          }
          else{
            this.data.lists[j].checked = false
          }
        }
      }
    }  
    for (let j = 0; j < listss.length; j++) {
      if(batchIds.length<=0)
      {
        this.data.listss[j].checked = false
      }
      else
      {
        for (let index = 0; index < batchIds.length; index++) {
          if(parseInt(batchIds[index]) === parseInt(listss[j].id))
          {
            this.data.listss[j].checked = true
            break;
          }
          else{
            this.data.listss[j].checked = false
          }
        }
      }
    }  
      console.info(list);
      console.info(lists);
      console.info(listss);
      this.setData({
        showModal:true,
        list:list,
        lists:lists,
        listss:listss
      })
    },
    // 禁止屏幕滚动
    preventTouchMove:function () {
    },
    // 弹出层里面的弹窗
    ok:function () {
      let name = '';
      let left = this.data.batchLeftIds;
      let content = this.data.batchContentIds;
      let right = this.data.batchRightIds;
      var list = this.data.list;
      var lists = this.data.lists;
      var listss = this.data.listss;
      for (let index = 0; index < left.length; index++) {
        for (let i = 0; i < list.length; i++) {
          if(left[index] == list[i].id)
          {
            name +=list[i].name+",";
            break;
          }
        }
      }
      for (let index = 0; index < content.length; index++) {
        for (let i = 0; i < lists.length; i++) {
          if(content[index] == lists[i].id)
          {
            name +=lists[i].name+",";
            break;
          }
        }
      }
      for (let index = 0; index < right.length; index++) {
        for (let i = 0; i < listss.length; i++) {
          if(right[index] == listss[i].id)
          {
            name +=listss[i].name+",";
            break;
          }
        }
      }
      name = name.substring(0, name.lastIndexOf(','));
      console.info()
      var ids = [];
      if(this.data.batchLeftIds.length>0)
      {
       ids = this.data.batchLeftIds.concat(this.data.batchContentIds.concat(this.data.batchRightIds))
      }
      else if(this.data.batchContentIds.length>0)
      {
        ids = this.data.batchContentIds.concat(this.data.batchLeftIds.concat(this.data.batchRightIds));
      }
      if(this.data.batchRightIds.length>0)
      {
        ids = this.data.batchRightIds.concat(this.data.batchLeftIds.concat(this.data.batchContentIds));
      }
      console.info(ids);
      this.setData({
        showModal:false,
        [`formData.batchIds`]: ids,
        batchName:name
      })
    },
    no:function(){
      this.setData({
        showModal:false
      })
    },
    checkboxLeftChange:function(e){
      this.setData({
        batchLeftIds: e.detail.value,//单个选中的值
      })
      console.info(this.data.batchLeftIds);
    },
    checkboxContentChange:function(e){
      this.setData({
        batchContentIds:e.detail.value,
      })
      console.info(this.data.batchContentIds);
    },
    checkboxRightChange:function(e){
      this.setData({
        batchRightIds:e.detail.value,
      })
      console.info(this.data.batchRightIds);
    },
    bindBusinessLicense: function(e) {
      console.log('picker country 发生选择改变，携带值为', e.detail.value);
  
      this.setData({
          licenseIndex: e.detail.value,
          [`formData.licenseIndex`]: e.detail.value
      })
    },

    submitForm: function() {
      var data = this.data.formData;
      console.info(data);
    },

    onLoad: function(option) {
      var that = this;
      that.setData({
        custId:option.custId,
          [`formData.custId`]: option.custId
      });
      var data = that.data.formData;
  }
  }
});